cli-qa
Command-line Questions & Answers. Supports color formatting, lists, yes/no confirmations.
Install
$ npm install cli-qa
Usage
var NewQA = require('cli-qa')
var QA = NewQA()
QA.ask("{white}Name:{reset}")
QA.ask({ title: "Username:", default: process.env.USER })
QA.ask({ key: "email", title: "E-Mail:", expect: { email: true } })
QA.ask({ title: "{red}Favorite foods:{reset}", list: 3 })
QA.ask({ key: "books", title: "{white}Favorite books:{reset}", list: true })
QA.ask({ title: "{yellow}Favorite {green}Fruits{reset}:", commaList: true })
QA.ask({ key: 'thatsAll', title: "{yellow}That's all, {name}? (yes/no){reset}", yesno: true })
QA.start(function (answers) {
console.log(answers)
})
Reference
The list of available options for each question:
key
The key that will be used in the answers object. If not specified, it'll be auto-generated
title
Title of the question. styling accepted.
list
If a numeric value is passed, user will be prompted to enter a list with expected number of lines. If true passed, the list input won't be limited.
commaList
Specify "true" if a comma-separated list is expected as an answer
yesno
Yes/no question? true/false
default
Default value if answer is empty.
expect
Specify requirements for validating the user input.
validate
Async validation function. See tests for example.